<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
       <div class="shuxing">
      <el-form-item label="行政区域" prop="areaId">
              <treeselect class="shuxing1" v-model="queryParams.areaId" :options="areaList" :normalizer="normalizer" placeholder="选择区域" />
        </el-form-item>
          </div>
        <el-form-item label="主体名称" prop="enterName">
        <el-input
          v-model="queryParams.enterName"
          placeholder="请输入主体名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基地名称" prop="baseName">
        <el-input
          v-model="queryParams.baseName"
          placeholder="请输入基地名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['supervise:superviseInfo:add']"
        >新增</el-button>
      </el-col>
     <!--  <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['supervise:superviseInfo:edit']"
        >修改</el-button>
      </el-col> -->
     <!--  <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['supervise:superviseInfo:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['supervise:superviseInfo:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="superviseInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="主体名称" align="center" prop="enterName" />
      <el-table-column label="基地名称" align="center" prop="baseName" />
      <el-table-column label="监测单位名称" align="center" prop="enterName" />
      <el-table-column label="监测单位电话" align="center" prop="superviseMobile" />
      <!-- <el-table-column label="环境情况" align="center" prop="envSuperviseInfo" />
      <el-table-column label="监测结果" align="center" prop="monitorResult" />
      <el-table-column label="周边污染" align="center" prop="pollutionControl" />
      <el-table-column label="环境情况" align="center" prop="environmentalScience" />
      <el-table-column label="附件" align="center" prop="attrute" /> 
      <el-table-column label="基地名称" align="center" prop="baseName" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['supervise:superviseInfo:edit']"
          >详情</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['supervise:superviseInfo:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改监测信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" disabled>
        <el-form-item label="主体名称" prop="enterName">
          <el-input v-model="form.enterName" placeholder="请输入基地编号" />
        </el-form-item>
         <el-form-item label="基地名称" prop="baseName">
          <el-input v-model="form.baseName" placeholder="请输入基地编号" />
        </el-form-item>
        <el-form-item label="监测单位名称" prop="enterName">
          <el-input v-model="form.enterName" placeholder="请输入监测单位名称" />
        </el-form-item>
        <el-form-item label="监测单位电话" prop="superviseMobile">
          <el-input v-model="form.superviseMobile" placeholder="请输入监测单位电话" />
        </el-form-item>
        <el-form-item label="执行标准" prop="executiveStandards">
          <el-input v-model="form.executiveStandards" placeholder="请输入执行标准" />
        </el-form-item>
        <el-form-item label="环境情况" prop="envSuperviseInfo">
          <el-input v-model="form.envSuperviseInfo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="监测结果" prop="monitorResult">
          <el-input v-model="form.monitorResult" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="周边污染" prop="pollutionControl">
          <el-input v-model="form.pollutionControl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="环境情况" prop="environmentalScience">
          <el-input v-model="form.environmentalScience" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="附件" prop="baseName">
          <el-input v-model="form.attrute" type="textarea" placeholder="请输入内容" />
        </el-form-item>
       
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSuperviseInfo, getSuperviseInfo, delSuperviseInfo, addSuperviseInfo, updateSuperviseInfo, exportSuperviseInfo } from "@/api/supervise/superviseInfo";
import {
 getTree
} from "@/api/enterpriseInfo/EnterpriseInfo";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "SuperviseInfo",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 监测信息表格数据
      superviseInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      areaList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        baseName: undefined,
        enterName: undefined,
        areaId: undefined,
        superviseName: undefined,
        superviseMobile: undefined,
        executiveStandards: undefined,
        envSuperviseInfo: undefined,
        monitorResult: undefined,
        pollutionControl: undefined,
        environmentalScience: undefined,
        attrute: undefined,
        baseId: undefined,
        enterId: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getTreeList();
  },
  methods: {
    /** 查询监测信息列表 */
    getList() {
      this.loading = true;
      listSuperviseInfo(this.queryParams).then(response => {
        this.superviseInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     getTreeList() {
       getTree().then(response => {
	        this.areaList = this.handleTree(response.data, "id");
      });
    },
     /** 转换部门数据结构 */
    normalizer(node) {
      console.log(JSON.stringify(node)+"11111111111111111111111111111111111111111111111111111")
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.label,
        children: node.children
      };
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        superviseName: undefined,
        superviseMobile: undefined,
        executiveStandards: undefined,
        envSuperviseInfo: undefined,
        monitorResult: undefined,
        pollutionControl: undefined,
        environmentalScience: undefined,
        attrute: undefined,
        baseId: undefined,
        enterId: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "监测信息详情";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSuperviseInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "监测信息详情";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateSuperviseInfo(this.form).then(response => {
              if (response.code == 0) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addSuperviseInfo(this.form).then(response => {
              if (response.code == 0) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除监测信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSuperviseInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有监测信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSuperviseInfo(queryParams);
        }).then(response => {
          this.download(response.data);
        }).catch(function() {});
    }
  }
};
</script>
<style lang="scss" scoped>

.shuxing {
  width: 250px;
  float: left;
  .shuxing1{
    width: 150px !important;
    height: 35px;
  }
  
}
</style>